<?php

class User_Form_User extends Front_Base_Form_Horizontal
{

    public function getFormId()
    {
        $className = get_class($this);
        return strtolower($className);
    }

    public function init()
    {
        $this->setIsArray(true);
        //$this->setElementsBelongTo('bootstrap');

        $this->_addClassNames('form-horizontal');
        
        // Email
        $this->addElement('text', 'email', array(
            'id' => 'dangky_email',
            'label' => $this->getView()->translate('EMAIL'),
            'maxlength' => 100,
            'class' => 'inputBox input1'
        ));
        $this->getElement('email')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('stringLength', false, array(3, 100)),
            array('EmailAddress')
        ));
        
        // Password
        $this->addElement('password', 'password', array(
            'id' => 'dangky_matkhau',
            'label' => $this->getView()->translate('PASSWORD'),
            'maxlength' => 255,
            'class' => 'inputBox input1',
            'autocomplete' => 'off'
        ));
        $this->getElement('password')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('stringLength', false, array(6, 255)),
        ));
        
        // Confirm Password
        $this->addElement('password', 'confirmpwd', array(
            'id' => 'dangky_matkhau2',
            'maxlength' => 255,
            'class' => 'inputBox input1',
            'autocomplete' => 'off'
        ));
        $this->getElement('confirmpwd')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('Identical', false, array('token' => 'password', 'messages' => array('notSame' => $this->getView()->translate('notSamePassword')))),
            array('stringLength', false, array(6, 255)),
        ));

        // Username
        $this->addElement('text', 'username', array(
            'id' => 'dangky_tensudung',
            'label' => $this->getView()->translate('USERNAME'),
            'description' => $this->getView()->translate('USERNAME_DESCRIPTION'),
            'maxlength' => 20,
            'class' => 'inputBox input1'
        ));
        $this->getElement('username')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->addFilter('StringToLower')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('Alnum', true),
            array('stringLength', false, array(6, 20)),
        ));

        // Fullname
        $this->addElement('text', 'fullname', array(
            'id' => 'dangky_tendaydu',
            'label' => $this->getView()->translate('FULLNAME'),
            'maxlength' => 45,
            'class' => 'inputBox input1'
        ));
        $this->getElement('fullname')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('stringLength', false, array(3, 45)),
        ));
        
        // Gender
        $this->addElement('select', 'gender', array(
            'id' => 'dangky_gioitinh',
            'label' => $this->getView()->translate('GENDER'),
            'class' => 'inputBox input2',
            'multiOptions' => array('1' => $this->getView()->translate('MALE'), '0' => $this->getView()->translate('FEMALE'))
        ));
        $this->getElement('gender')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true)
        ));
        
        // Day
        $day = array();
        $day[0] = $this->getView()->translate('DAYDAY');
        for($i=1; $i<=31; $i++) {
            $value = sprintf('%02d', $i);
            $day[$value] = $value;
        }
        $this->addElement('select', 'dd', array(
            'id' => 'dangky_ngaysinh',
            'label' => $this->getView()->translate('DATEOFBIRTH'),
            'class' => 'inputBox input2',
            'multiOptions' => $day
        ));
        $this->getElement('dd')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('Digits', true),
            array('stringLength', false, array(2)),
        ));
        
        // Month
        $month = array();
        $month[0] = $this->getView()->translate('MONTHMONTH');
        for($i=1; $i<=12; $i++) {
            $value = sprintf('%02d', $i);
            $month[$value] = $value;
        }
        $this->addElement('select', 'mm', array(
            'id' => 'dangky_thangsinh',
            'class' => 'inputBox input2',
            'multiOptions' => $month
        ));
        $this->getElement('mm')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('Digits', true),
            array('stringLength', false, array(2)),
        ));
        
        // Year
        $year = array();
        $year[0] = $this->getView()->translate('YYYY');
        for($i=1930; $i<date('Y'); $i++) {
            $value = sprintf('%04d', $i);
            $year[$value] = $value;
        }
        $this->addElement('select', 'yyyy', array(
            'id' => 'dangky_namsinh',
            'class' => 'inputBox input3',
            'description' => $this->getView()->translate('DATEOFBIRTH_DESCRIPTION'),
            'multiOptions' => $year
        ));
        $this->getElement('yyyy')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('Digits', true),
            array('stringLength', false, array(4)),
        ));

        // Phone number
        $this->addElement('text', 'phone', array(
            'id' => 'dangky_dienthoai',
            'label' => $this->getView()->translate('PHONE'),
            'description' => $this->getView()->translate('PHONE_DESCRIPTION'),
            'maxlength' => 20,
            'class' => 'inputBox input1'
        ));
        $this->getElement('phone')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('stringLength', false, array(10, 20)),
        ));

        // Address
        $this->addElement('text', 'address', array(
            'id' => 'dangky_diachicodinh',
            'label' => $this->getView()->translate('ADDRESS'),
            'value' => $this->getView()->translate('ADDRESS_VALUE'),
            'maxlength' => 255,
            'class' => 'inputBox input4'
        ));
        $this->getElement('address')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('stringLength', false, array(1, 255)),
        ));
        
        // City
        $city = array();
        $city[0] = $this->getView()->translate('ADDRESS_CITY');
        $this->addElement('select', 'city', array(
            'id' => 'dangky_thanhpho',
            'class' => 'inputBox input5 input6',
            'multiOptions' => $city
        ));
        $this->getElement('city')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('Digits', true)
        ));
        
        // District
        $district = array();
        $district[0] = $this->getView()->translate('ADDRESS_DISTRICT');
        $this->addElement('select', 'district', array(
            'id' => 'dangky_quanhuyen',
            'class' => 'inputBox input5',
            'multiOptions' => $district
        ));
        $this->getElement('district')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('Digits', true)
        ));
        
        // Ward
        $ward = array();
        $ward[0] = $this->getView()->translate('ADDRESS_WARD');
        $this->addElement('select', 'ward', array(
            'id' => 'dangky_phuongxa',
            'class' => 'inputBox input5',
            'multiOptions' => $ward
        ));
        $this->getElement('ward')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('Digits', true)
        ));
        
        // Agreement
        $this->addElement('checkbox', 'agreement', array(
            'id' => 'dangky_dongy',
            'class' => 'input7'
        ));
        $this->getElement('agreement')
        ->addFilter('StringTrim')
        ->addFilter('StripTags')
        ->setRequired(true)
        ->addValidators(array(
            array('NotEmpty', true),
            array('Digits', true),
            new Zend_Validate_InArray(array(1))
        ));

        /*
        // Images
        $config = Zend_Registry::get('configuration');
        $this->addElement('file', 'file', array(
            'id' => $this->getFormId() . '_file',
            'label' => $this->getView()->translate('PHOTO')
        ));
        $this->getElement('file')
        ->setDestination($config->upload->path . DS . 'images' . DS . 'users')
        ->addValidators(array(
            array('Count', false, 1),
            array('Size', false, $config->upload->image->maxsize),
            array('Extension', false, explode(',', $config->upload->image->extension)),
            array('IsImage', false, array('magicfile' => false))
        ));

        // Images preview
        $this->addElement('render', 'image', array(
            'id' => $this->getFormId() . '_image',
            'viewPath' => 'form/element-user-image-preview.phtml',
            'width' => '120px',
            'height' => '160px'
        ));

        // DOB preview
        $this->addElement('render', 'dob', array(
            'id' => $this->getFormId() . '_dob',
            'label' => $this->getView()->translate('DOB'),
            'readonly' => 'readonly',
            'format' => 'dd-mm-yyyy',
            'viewPath' => 'form/element-datetime-picker.phtml'
        ));*/

        // Id
        $this->addElement('hidden', 'id', array(
            'id' => $this->getFormId() . '_id'
        ));
        $this->getElement('id')->removeDecorator('Wrapper')->removeDecorator('HtmlTag');
    }

}